package com.xbongbong.saas.domain.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.util.RegexUtil;
import com.xbongbong.paas.toolbox.wrap.Entity;
import com.xbongbong.paas.toolbox.wrap.QueryIgnore;
import lombok.Getter;
import lombok.Setter;

/**
 * 阶段工作
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/2/13 10:41
 * @since v1.0
 */
@Getter
@Setter
public class StageWorkEntity extends Entity {
    /**
     * id
     */
    private Long id;
    /**
     * 公司id
     */
    private String corpid;
    /**
     * 表单id
     */
    private Long formId;
    /**
     * 关联业务类型
     */
    private Integer businessType;
    /**
     * 阶段工作名称
     */
    private String name;
    /**
     * 是否必填
     */
    private Integer required;
    /**
     * 排序值
     */
    private Integer sort;
    /**
     * 阶段code
     */
    private String stageCode;
    /**
     * 关联阶段流程id
     */
    private Long stageProcessId;
    /**
     * 关联流程id
     */
    private Long stageId;
    /**
     * saas标记
     */
    private Integer saasMark;
    /**
     * 任务描述
     */
    private String description;
    /**
     * 任务占比
     */
    private Integer proportion;
    /**
     * 执行事件
     */
    private JSONObject executionEvent;
    /**
     * 执行人
     */
    private JSONArray executor;
    /**
     * 任务完成条件
     */
    private JSONArray completionCondition;
    /**
     * 删除标志
     */
    private Integer del;
    /**
     * 创建时间
     */
    private Long addTime;
    /**
     * 更新时间
     */
    private Long updateTime;

    /**
     * 是否是新增或者编辑的任务 true代表是
     */
    @Getter(onMethod_ = {@QueryIgnore})
    private Boolean isEdit;

    public StageWorkEntity() {
        this.del = 0;
    }

    public StageWorkEntity(String corpid, Long formId, Integer businessType, String name, Integer required, Integer sort, String stageCode, Long stageProcessId, Long stageId, Integer saasMark, String description, Integer proportion, JSONObject executionEvent, JSONArray executor, JSONArray completionCondition, Integer del) {
        this.corpid = corpid;
        this.formId = formId;
        this.businessType = businessType;
        this.name = name;
        this.required = required;
        this.sort = sort;
        this.stageCode = stageCode;
        this.stageProcessId = stageProcessId;
        this.stageId = stageId;
        this.saasMark = saasMark;
        this.description = description;
        this.proportion = proportion;
        this.executionEvent = executionEvent;
        this.executor = executor;
        this.completionCondition = completionCondition;
        this.del = del;
        this.setAddTime(DateTimeUtil.getInt());
        this.setUpdateTime(DateTimeUtil.getInt());
    }

    public String getName() {
        return RegexUtil.getVariableName(name);
    }

}
